Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes the DT ajax error #312

Merged
merged 7 commits into from
Oct 4, 2024
Merged

Fixes the DT ajax error #312

merged 7 commits into from
Oct 4, 2024

Conversation

vedhav
Copy link
Contributor

@vedhav vedhav commented Oct 2, 2024

Closes #284

Currently, the implementation is only done for the tm_g_gh_correlationplot so please test the example for this module alone:

devtools::load_all()

data <- teal_data()
data <- within(data, {
  library(dplyr)
  library(stringr)

  # use non-exported function from goshawk
  h_identify_loq_values <- getFromNamespace("h_identify_loq_values", "goshawk")

  # original ARM value = dose value
  arm_mapping <- list(
    "A: Drug X" = "150mg QD",
    "B: Placebo" = "Placebo",
    "C: Combination" = "Combination"
  )
  color_manual <- c("150mg QD" = "#000000", "Placebo" = "#3498DB", "Combination" = "#E74C3C")
  # assign LOQ flag symbols: circles for "N" and triangles for "Y", squares for "NA"
  shape_manual <- c("N" = 1, "Y" = 2, "NA" = 0)

  set.seed(1)
  ADSL <- rADSL
  ADLB <- rADLB
  var_labels <- lapply(ADLB, function(x) attributes(x)$label)
  ADLB <- ADLB %>%
    mutate(AVISITCD = case_when(
      AVISIT == "SCREENING" ~ "SCR",
      AVISIT == "BASELINE" ~ "BL",
      grepl("WEEK", AVISIT) ~
        paste(
          "W",
          trimws(
            substr(
              AVISIT,
              start = 6,
              stop = str_locate(AVISIT, "DAY") - 1
            )
          )
        ),
      TRUE ~ NA_character_
    )) %>%
    mutate(AVISITCDN = case_when(
      AVISITCD == "SCR" ~ -2,
      AVISITCD == "BL" ~ 0,
      grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)),
      TRUE ~ NA_real_
    )) %>%
    # use ARMCD values to order treatment in visualization legend
    mutate(TRTORD = ifelse(grepl("C", ARMCD), 1,
      ifelse(grepl("B", ARMCD), 2,
        ifelse(grepl("A", ARMCD), 3, NA)
      )
    )) %>%
    mutate(ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))])) %>%
    mutate(ARM = factor(ARM) %>%
      reorder(TRTORD)) %>%
    mutate(
      ANRHI = case_when(
        PARAMCD == "ALT" ~ 60,
        PARAMCD == "CRP" ~ 70,
        PARAMCD == "IGA" ~ 80,
        TRUE ~ NA_real_
      ),
      ANRLO = case_when(
        PARAMCD == "ALT" ~ 20,
        PARAMCD == "CRP" ~ 30,
        PARAMCD == "IGA" ~ 40,
        TRUE ~ NA_real_
      )
    ) %>%
    rowwise() %>%
    group_by(PARAMCD) %>%
    mutate(LBSTRESC = ifelse(
      USUBJID %in% sample(USUBJID, 1, replace = TRUE),
      paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC
    )) %>%
    mutate(LBSTRESC = ifelse(
      USUBJID %in% sample(USUBJID, 1, replace = TRUE),
      paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC
    )) %>%
    ungroup()
  attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]]
  attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit"
  attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit"

  # add LLOQ and ULOQ variables
  ADLB_LOQS <- h_identify_loq_values(ADLB, "LOQFL")
  ADLB <- left_join(ADLB, ADLB_LOQS, by = "PARAM")
})

datanames <- c("ADSL", "ADLB")
datanames(data) <- datanames

join_keys(data) <- default_cdisc_join_keys[datanames]

app <- init(
  data = data,
  modules = modules(
    tm_g_gh_correlationplot(
      label = "Correlation Plot",
      dataname = "ADLB",
      param_var = "PARAMCD",
      xaxis_param = choices_selected(c("ALT", "CRP", "IGA"), "ALT"),
      yaxis_param = choices_selected(c("ALT", "CRP", "IGA"), "CRP"),
      xaxis_var = choices_selected(c("AVAL", "BASE", "CHG", "PCHG"), "BASE"),
      yaxis_var = choices_selected(c("AVAL", "BASE", "CHG", "PCHG"), "AVAL"),
      trt_group = choices_selected(c("ARM", "ACTARM"), "ARM"),
      color_manual = c(
        "Drug X 100mg" = "#000000",
        "Placebo" = "#3498DB",
        "Combination 100mg" = "#E74C3C"
      ),
      shape_manual = c("N" = 1, "Y" = 2, "NA" = 0),
      plot_height = c(500, 200, 2000),
      facet_ncol = 2,
      visit_facet = TRUE,
      reg_line = FALSE,
      loq_legend = TRUE,
      font_size = c(12, 8, 20),
      dot_size = c(1, 1, 12),
      reg_text_size = c(3, 3, 10),
      hline_arb = c(40, 50),
      hline_arb_label = "arb hori label",
      hline_arb_color = c("red", "blue"),
      hline_vars = c("ANRHI", "ANRLO", "ULOQN", "LLOQN"),
      hline_vars_colors = c("green", "blue", "purple", "cyan"),
      hline_vars_labels = c("ANRHI Label", "ANRLO Label", "ULOQN Label", "LLOQN Label"),
      vline_vars = c("ANRHI", "ANRLO", "ULOQN", "LLOQN"),
      vline_vars_colors = c("yellow", "orange", "brown", "gold"),
      vline_vars_labels = c("ANRHI Label", "ANRLO Label", "ULOQN Label", "LLOQN Label"),
      vline_arb = c(50, 70),
      vline_arb_label = "arb vert A",
      vline_arb_color = c("green", "orange")
    )
  )
)

shinyApp(app$ui, app$server)

@vedhav vedhav added bug Something isn't working core labels Oct 2, 2024
Copy link
Contributor

github-actions bot commented Oct 2, 2024

✅ All contributors have signed the CLA
Posted by the CLA Assistant Lite bot.

@vedhav
Copy link
Contributor Author

vedhav commented Oct 2, 2024

I have read the CLA Document and I hereby sign the CLA

Copy link
Contributor

github-actions bot commented Oct 2, 2024

badge

Code Coverage Summary

Filename                                 Stmts    Miss  Cover    Missing
-------------------------------------  -------  ------  -------  ---------
R/tm_g_gh_boxplot.R                        358     358  0.00%    175-600
R/tm_g_gh_correlationplot.R                559     559  0.00%    227-895
R/tm_g_gh_density_distribution_plot.R      281     281  0.00%    135-466
R/tm_g_gh_lineplot.R                       565     565  0.00%    161-820
R/tm_g_gh_scatterplot.R                    249     249  0.00%    144-445
R/tm_g_gh_spaghettiplot.R                  319     319  0.00%    194-595
R/toggleable_slider.R                      154     154  0.00%    72-243
R/utils-arbitrary_lines.r                  125     125  0.00%    19-176
R/utils-data_constraints.r                 190     190  0.00%    2-257
R/utils-keep_range_slider_updated.r         29      29  0.00%    9-45
R/utils-maptrt.r                             9       9  0.00%    24-36
R/utils-templ_ui.r                          48      48  0.00%    2-73
R/utils.R                                   49      49  0.00%    12-112
R/zzz.R                                      2       2  0.00%    2-3
TOTAL                                     2937    2937  0.00%

Diff against main

Filename                                 Stmts    Miss  Cover
-------------------------------------  -------  ------  --------
R/tm_g_gh_correlationplot.R                 +1      +1  +100.00%
R/tm_g_gh_density_distribution_plot.R       -1      -1  +100.00%
R/tm_g_gh_scatterplot.R                     +1      +1  +100.00%
R/tm_g_gh_spaghettiplot.R                   +1      +1  +100.00%
TOTAL                                       +2      +2  +100.00%

Results for commit: fb9af77

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

Copy link
Contributor

@m7pr m7pr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Require changes in other modules as well but this is excellent work. Will imrpve

R/tm_g_gh_correlationplot.R Outdated Show resolved Hide resolved
@m7pr
Copy link
Contributor

m7pr commented Oct 3, 2024

Hey @vedhav I don't see the plot - this is what we ended up on a live session, before we abandoned the debounce approach in here

image

@m7pr
Copy link
Contributor

m7pr commented Oct 3, 2024

@vedhav ignore my previous comment, something different must have happened and blocked the plot/browser. Now, when restarted, I can see the plot

Copy link
Contributor

@m7pr m7pr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vedhav I applied changes to other modules :)

Thanks for the help, would you mind having one last look?

@vedhav vedhav merged commit da72560 into main Oct 4, 2024
25 checks passed
@vedhav vedhav deleted the 248_debounce@main branch October 4, 2024 08:05
@github-actions github-actions bot locked and limited conversation to collaborators Oct 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: DT table ajax error on wrong column being selected.
2 participants